package org.opensmile.website.controller;

import javax.validation.Valid;

import org.opensmile.website.domain.RegisterBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value="/register")
public class RegisterController {
	
	@RequestMapping(method=RequestMethod.GET)
	public String register(Model model){
		model.addAttribute(new RegisterBean());
		return "register/input";
	}
	
	
	@RequestMapping(value="/save",method=RequestMethod.POST)
	public String save(@Valid RegisterBean registerBean,BindingResult result){
		if(result.hasErrors()){
			return "register/input";
		}
		return "redirect:/"+registerBean.getUsername();
	}
	
	
	
}
